<?php
    class ProductController extends Main_Controller_Action
    {
        public function init()
        {
            $this->loadTemplates();
        }
        
        public function categoryAction()
        {
            $cat_id = $this->_request->getParam('id');
            $category = new AdminDthink_Model_Category();
            $this->view->cat_id = $cat_id;
            $this->view->cat_name = $category->getCatNameById($cat_id);
            $this->view->headTitle('uMarket - ' . $this->view->cat_name);
            
            $product = new Default_Model_Product();
            $list = $product->listProductByCategory($cat_id);
            $adapter = new Zend_Paginator_Adapter_DbSelect($list);
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(15);
            $paginator->setPageRange(5);
            $currentPage = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->data = $paginator;
        }
        
        public function detailsAction()
        {
            $product_id = $this->_request->getParam('id');
            $product = new Default_Model_Product();
            $this->view->data = $product->getProductById($product_id);
            $content = preg_replace('/\s+/', ' ', $this->view->data['content_plaintext']);
            $content = $product->cut_string($content, 600, 1);
            $this->view->image = $this->view->data['product_image'];
            $this->view->title = $this->view->data['sort_name'];
            $this->view->description = $content;
            $this->view->headTitle('uMarket - ' . $this->view->data['product_name']);
        }
    }
